package com.dk.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class CorsFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest re =  (HttpServletRequest)request;
        HttpServletResponse rp =  (HttpServletResponse)response;
        String origin = re.getHeader("Origin");
        rp.setHeader("Access-Control-Allow-Origin",origin);
        rp.setHeader("Access-Control-Allow-Methods","POST,GET");
        chain.doFilter(re,rp);
    }

    @Override
    public void destroy() {

    }
}
